#ifndef XDEVICE_CONSENSUS_H
#define XDEVICE_CONSENSUS_H

#include <xdevice/xdevice.h>

#ifdef __cplusplus
extern "C" {
#endif

/* 前向声明 */
typedef struct xdevice_consensus xdevice_consensus_t;

/* 共识模块API */
xdevice_consensus_t* xdevice_consensus_create(const char* data_dir, int node_id, int cluster_size);
void xdevice_consensus_destroy(xdevice_consensus_t* consensus);

int xdevice_consensus_start(xdevice_consensus_t* consensus);
int xdevice_consensus_stop(xdevice_consensus_t* consensus);

/* 设备操作API */
int xdevice_consensus_create_device(xdevice_consensus_t* consensus, const char* name, uint64_t size, xdevice_storage_type_t storage_type);
int64_t xdevice_consensus_read(xdevice_consensus_t* consensus, const char* name, uint64_t offset, void* buffer, size_t length);
int64_t xdevice_consensus_write(xdevice_consensus_t* consensus, const char* name, uint64_t offset, const void* buffer, size_t length);
int xdevice_consensus_sync(xdevice_consensus_t* consensus, const char* name);

/* 信息查询API */
int xdevice_consensus_get_cluster_info(xdevice_consensus_t* consensus, xdevice_cluster_info_t* info);
int xdevice_consensus_list_devices(xdevice_consensus_t* consensus, char names[][XDEVICE_MAX_DEVICE_NAME], int max_count);

/* 存储后端注册函数声明 */
int xdevice_storage_local_register(void);
int xdevice_storage_mock_register(void);

#ifdef __cplusplus
}
#endif

#endif /* XDEVICE_CONSENSUS_H */
